import sys, pygame, ezmenu, game
from scenes import *

class Menu(object):
    def __init__(self, screen):

        pygame.init()
        pygame.display.set_caption("Menu")
        self.screen = screen
        self.keepGoing = True

        self.menu = ezmenu.EzMenu(
            ["New Game", lambda: self.new_game()],
            ["Help", lambda: self.help(self.screen)],
            ["Quit Game", lambda: self.quit()])

        self.menu.center_at(320, 240)
        self.menu.set_font(pygame.font.Font(filepath("fonts/font2.ttf"), 64))
        self.menu.set_highlight_color((0, 255, 0))
        self.menu.set_normal_color((255, 255, 255))
       
        self.main_loop()
 
    def new_game(self):
        game.Game(self.screen) 
        
    def help(self, screen):
        cutscene(screen, ["HELP",
        "",
        "Move: Arrow Keys",
        "Fire: Spacebar",
        "Return: Esc",
        "Note: Don't get hit!",
        ""])
    
    def quit(self):
        sys.exit()
        
    def main_loop(self):
        while self.keepGoing:
    
            self.events = pygame.event.get()
    
            self.menu.update(self.events)
    
            for e in self.events:
                if e.type == pygame.QUIT:
                    sys.exit()
                elif e.type == pygame.KEYDOWN:
                    if e.key == pygame.K_ESCAPE:
                        self.keepGoing = False
    
            self.screen.fill((0, 0, 0))
            self.menu.draw(self.screen)
            pygame.display.flip()
